package com.dong.cutesms.components;

import com.dong.cutesms.R;
import com.dong.cutesms.activitys.MainActivity;
import com.dong.cutesms.constant.AppParameters;
import com.dong.cutesms.utils.SmsUtils;

import android.app.Activity;
import android.app.Dialog;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.provider.Contacts.People;
import android.provider.ContactsContract;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

public class DialogActionThread{
	private Context context;
	private Dialog dialog;
	private SmsUtils smsUtils;
	private int contactID;
	
	public DialogActionThread(Context _context) {
		this.context = _context;
		smsUtils = new SmsUtils(context.getContentResolver(), context);
		dialog = new Dialog(context);
		dialog.setContentView(R.layout.dialog_action_thread);
		contactID = smsUtils.getContactIDByNameAndPhoneNumber(
				AppParameters.people.displayName,
				AppParameters.people.phoneNumber);
		TextView addorview_contact = (TextView) dialog.findViewById(R.id.addorview_contact);
		if(contactID==-1){
			addorview_contact.setText(R.string.add_contact);
		}
		else{
			addorview_contact.setText(R.string.view_contact);
		}
		dialog.getWindow().setBackgroundDrawable(
				new ColorDrawable(Color.TRANSPARENT));
		dialog.show();
		setOnClickListener();
	}

	public Dialog getInstance() {
		return dialog;
	}

	private void setOnClickListener() {
		LinearLayout delete_thread = (LinearLayout) dialog
				.findViewById(R.id.btn_delete_thread);
		delete_thread.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				dialog.dismiss();
				int threadID = AppParameters.people.threadID;
				smsUtils.removePeople(threadID);
				AppParameters.listPeople.remove(AppParameters.people);
				MainActivity.adapter.notifyDataSetChanged();
			}
		});
	}
	
	
}
